/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-27
 * Time: 10:23
 */
public class test5 {

    public static final long COUNT = 20_0000_0000;
    public static void serial(){
        long start = System.currentTimeMillis();
        long a = 0;
        for(int i =0;i<COUNT;++i){
            a++;
        }
        a = 0;
        for(int i =0;i<COUNT;++i){
            a++;
        }
        long end = System.currentTimeMillis();
        System.out.println("单线程所消耗的时间" + (end - start) + "ms");
    }

    public static void currency(){
        long start = System.currentTimeMillis();
        Thread t1 = new Thread(()->{;
            long a = 0;
            for(int i =0;i<COUNT;++i){
                a++;
            }
        });
        Thread t2 = new Thread(()->{
            long a = 0;
            for(int i =0;i<COUNT;++i){
                a++;
            }
        });
        t1.start();
        t2.start();
        try {
            t1.join();//等待t1线程结束任务在执行下一个
            t2.join();//等待t2线程结束任务在执行,如果没有任务就返回/退出
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        long end = System.currentTimeMillis();
        System.out.println("多线程所消耗的时间" + (end - start) + "ms");
    }


    public static void main(String[] args) {
        serial();
        currency();
    }


}
